import HttpRequest from "@/domain/HttpRequest";
import HttpResponse from "@/domain/HttpResponse";
import axios from "axios";

const instance = axios.create({
    timeout: 5000
});

export default function http<T = string, D = any>(config: HttpRequest<D>): Promise<HttpResponse<T>> {
    return new Promise<HttpResponse<T>>((resolve, reject) => {
        instance({
            ...config,
            responseType: 'arraybuffer'
        }).then(response => {
            resolve(response as any);
        }).catch(e => reject(e));
    });
};